<style lang="less">
@import '../../../assets/style/celiang.less';
</style>

<template>
    <mxq-router-layout>
        <div class="celiang">
            <Head slot="header" @headerClick="headerClick($event)">
                <div slot="headerTitle">
                    <span>测量记录</span>
                </div>
                <div slot="headerRight">
                    <i class="iconfont icon-shouye"/>
                    <!-- <van-icon class="home" name="home"/> -->
                </div>
            </Head>
            <van-cell-group class="box1">
                <van-cell title="接地电阻测量" class="tit"/>
                <van-field
                    v-model="formItem.numberA"
                    type="number"
                    label="A"
                    placeholder="请输入"/>
                <van-field
                    v-model="formItem.numberB"
                    type="number"
                    label="B"
                    placeholder="请输入"/>
                <van-field
                    v-model="formItem.numberC"
                    type="number"
                    label="C"
                    placeholder="请输入"/>
                <van-field
                    v-model="formItem.numberD"
                    type="number"
                    label="D"
                    placeholder="请输入"/>
                <p class="cl_text" @click="echoMeasure1()">历史测量记录</p>
            </van-cell-group>
            <!--接地电阻测量历史记录弹出框-->
            <van-popup v-model="first" class="popup_box">
                <van-cell title="接地电阻测量" class="tit"/>
                <div class="box" v-for="(item,index) in echoData1" :key="index">
                    <van-field
                        style="width:100%"
                        v-model="time1"
                        label="创建时间:"
                        :placeholder="item.CREATE_TIME?item.CREATE_TIME:'无'"
                        disabled/>
                    <van-field
                        v-model="item.A"
                        type="number"
                        label="A:"
                        :placeholder="item.A?item.A:'无'"
                        disabled/>
                    <van-field
                        v-model="item.B"
                        type="number"
                        label="B:"
                    :placeholder="item.B?item.B:'无'"
                    disabled/>
                    <van-field
                        v-model="item.C"
                        type="number"
                        label="C:"
                        :placeholder="item.C?item.C:'无'"
                        disabled/>
                    <van-field
                        v-model="item.D"
                        type="number"
                        label="D:"
                        :placeholder="item.D?item.D:'无'"
                        disabled/>
                </div>
            </van-popup>
            
            <van-cell-group>
                <van-cell title="交叉跨越测量" class="tit"/>
                <van-field
                    id="area"
                    v-model="cellArea.message"
                    type="textarea"
                    placeholder="请输入"
                    rows="5"
                    autosize/>
                <p class="cl_text" @click="echoMeasure2()">历史测量记录</p>
            </van-cell-group>
            
            <!--交叉跨越测量历史记录弹出框-->
            <van-popup v-model="second"  class="popup_box">
                <van-cell title="交叉跨越测量" class="tit"/>
                <div class="box" v-for="(item,index) in echoData2" :key="index">
                    <van-field
                        style="width:100%;"
                        v-model="time2"
                        label="创建时间:"
                        :placeholder="item.CREATE_TIME?item.CREATE_TIME:'无'"
                        class="title"
                        disabled/>
                    <!--  <van-field
                        style="width:100%;"
                        id="area"
                        v-model="message"
                        label="交叉跨越测量:"
                        type="textarea"
                        :placeholder="item.OVERLAPPING?item.OVERLAPPING:'无'"
                        rows="3"
                        autosize
                        disabled/> -->
                        
                    <van-field
                        style="width:100%;border-bottom:1px solid gray;"
                        id="area"
                        v-model="message"
                        label="内容:"
                        type="textarea"
                        :placeholder="item.OVERLAPPING?item.OVERLAPPING:'无'"
                        rows="3"
                        autosize
                        disabled/>
                </div>
            </van-popup>
            <van-button size="large" type="primary" v-if="$route.query.towerStatus!=2"  @click="upLoad">上传测量记录</van-button>
        </div>
    </mxq-router-layout>
</template>

<script>
import Head from '../../../components/head'
import AsyncValidator from "async-validator"
import { callData } from '../../../axios/axios'
import {
    Cell,
    CellGroup,
    Field,
    Icon,
    Button,
    Popup,
    Toast
} from 'vant';

export default {
	name: 'cgxs_ceLiang',
    components: {
        Head,
        [Cell.name]: Cell,
        [CellGroup.name]: CellGroup,
        [Field.name]: Field,
        [Button.name]: Button,
        [Icon.name]: Icon,
        [Popup.name]: Popup
    },
    data() {
        return {
        	first:false,
			second:false,
			time1:"",//创建时间
            time2:"",//创建时间
			message:"",//交叉测量内容
        	echoData:{},
        	echoData1:[],
        	echoData2:[],
        	formItem:{
        		numberA: "",
	            numberB: "",
	            numberC: "",
                numberD: ""
			},
			cellArea: {
                message: ""
			},
            message:"",
            rulesJDDZ: {//接地电阻非空验证
            	numberA:{required:true,message:'接地电阻测量A不可为空'},
				numberB:{required:true,message:'接地电阻测量B不可为空'},
				numberC:{required:true,message:'接地电阻测量C不可为空'},
				numberD:{required:true,message:'接地电阻测量D不可为空'}
            },
            rulesJCKY:{//交叉跨越非空验证
               message:{required:true,message:'交叉跨越测量不可为空'},
			},
            getEchoData: [],//获取回显数据
            params: this.$route.query
        }
    },
    mounted(){
    	this.echoMeasure();
    },
    methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			this.$router.push({name:"index"})
		},
		upMeasure(){
            var params = {};
            params.a = this.formItem.numberA;
            params.b = this.formItem.numberB;
            params.c = this.formItem.numberC;
            params.d = this.formItem.numberD;
            params.overlapping = this.cellArea.message;
            params.towerId = this.$route.query.towerId;
            params.lineTowerId = this.$route.query.lineTowerId;
            params.taskId = this.$route.query.taskId;
            params.towerTaskId = this.$route.query.towerTaskId;
			//修改
        	if (this.formItem.id) {
        		params['id'] = this.formItem.id
        	}
            callData('/accountServer/CmMeasure/appAddMeasure', 'post', params).then(res => {
                if(res.success){
                    Toast(res.data)
                    let query = {
                        xsId: this.params.xsId,
                        xsTowerTaskId: this.params.xsTowerTaskId,
                        lineTowerId: this.params.lineTowerId,
                        taskId: this.params.taskId,
                        towerId: this.params.towerId,
                        towerName: this.params.towerName,
                        lineId: this.params.lineId,
                        jdUserId: this.params.jdUserId,
                        lineName: this.params.lineName,
                        phoType: this.params.phoType,//拍照必拍项
                        status:  this.params.status,
                        taskEndTime: this.params.taskEndTime,//任务结束时间
                        taskStatus:this.params.taskStatus,//任务状态
                        towerStatus: this.params.towerStatus,//杆塔状态
                        needMeasure: this.params.needMeasure,//测量限制
                        towerTaskId: this.params.towerTaskId,
                        towerName: this.params.towerName,
                        index: this.params.index,	//taskType任务类型
                        page: this.params.page,
                        size: this.params.size
                    }
                    this.$router.push({
                        path: 'cgxs_allowPhotos',
                        query
                    });
                }
                else {
                    Toast(res.data)
                }
            })
		},
        // 非空验证
        yanzheng(i){
            if(i==2){
                var validatorJCKY = new AsyncValidator(this.rulesJCKY);
                validatorJCKY.validate(this.cellArea,(valid2)=>{
                    if (!valid2) {// 验证通过
                        this.$emit('upLoad', this.cellArea)
                        if(i==2 || i==3 ){
                            this.upMeasure();
                            return false;
                        }
                    } else {// 验证失败
                        Toast.fail(valid2[0].message)
                    }
                });
                return false
            }
            var validatorJDDZ = new AsyncValidator(this.rulesJDDZ);
            validatorJDDZ.validate(this.formItem,(valid1)=>{
                if (!valid1) {// 验证通过
                    this.$emit('upLoad', this.formItem)
                    if(i==1){
                        this.upMeasure();
                        return false;
                    }
                    var validatorJCKY = new AsyncValidator(this.rulesJCKY);
                    validatorJCKY.validate(this.cellArea,(valid2)=>{
                        if (!valid2) {// 验证通过
                            this.$emit('upLoad', this.cellArea)
                            if(i==2 || i==3 ){
                                this.upMeasure();
                                return false;
                            }
                        } else {// 验证失败
                            Toast.fail(valid2[0].message)
                        }
                    });
                } else {// 验证失败
                    Toast.fail(valid1[0].message);
                }
            });
        },
		upLoad() {
            let needCL = this.$route.query.needMeasure;
            if(needCL==null){
                this.upMeasure()
            }
            else{
                let needMeasure = needCL.split(',')
                needMeasure.forEach((item,index) => {//接口返回的值
                    if (needMeasure.length == 1 && needMeasure[index] == 1) {
                        this.yanzheng(1);
                    }
                    if (needMeasure.length == 1 && needMeasure[index] == 2) {
                        this.yanzheng(2);
                    }
                    if (needMeasure.length == 2) {
                        if (needMeasure[index] == 2) {
                            return
                        }
                        this.yanzheng(3);
                    }
                })
            }
        },
        echoMeasure(){//回显
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        		taskId:this.$route.query.taskId,//任务id
        		towerTaskId:this.$route.query.towerTaskId//杆塔任务id
        	}).then(res => {
        		var echoData = res.data[0];
                console.log('echoData',echoData);
        		if(echoData){
        			this.formItem.id = echoData.ID;
        			this.formItem.numberA = echoData.A;
	        		this.formItem.numberB = echoData.B;
	        		this.formItem.numberC = echoData.C;
	        		this.formItem.numberD = echoData.D;
	        		this.cellArea.message = echoData.OVERLAPPING;
        		}
			})
        },
        echoMeasure1(){//历史记录1
        	this.first=true;
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        	}).then(res => {
        		this.echoData1 = res.data;
        		return false;
			})
        },
        echoMeasure2(){//历史记录2
        	this.second=true;
        	callData('/accountServer/CmMeasure/appFindMeasure', 'get', {
        		towerId:this.$route.query.towerId,//物理杆塔id
        		lineTowerId:this.$route.query.lineTowerId,//逻辑杆塔id
        	}).then(res => {
        		this.echoData2 = res.data;
        		return false;
			})
        }
    }
}
</script>
